<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="标题" prop="contentTitle">
        <el-input v-model="queryParams.contentTitle" placeholder="请输入标题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="类型" prop="contentType">
        <el-select v-model="queryParams.contentType" placeholder="请选择类型:" clearable>
          <el-option v-for="dict in dict.type.content_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="输入的手机号/用户名 非操作者的" prop="userName">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.userName"-->
      <!--          placeholder="请输入输入的手机号/用户名 非操作者的"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="发布者昵称" prop="publishNick">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.publishNick"-->
      <!--          placeholder="请输入发布者昵称"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="跳转链接" prop="bannerUrl">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.bannerUrl"-->
      <!--          placeholder="请输入跳转链接"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="内容模块" prop="contentCategory">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.contentCategory"-->
      <!--          placeholder="请输入内容模块"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="权重" prop="weight">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.weight"-->
      <!--          placeholder="请输入权重"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="仅会员可见" prop="onlyVip">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.onlyVip"-->
      <!--          placeholder="请输入仅会员可见"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="查看数" prop="viewNumber">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.viewNumber"-->
      <!--          placeholder="请输入查看数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="评论数" prop="commentNum">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.commentNum"-->
      <!--          placeholder="请输入评论数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:contentinfo:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:contentinfo:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:contentinfo:remove']">删除
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['system:contentinfo:export']"-->
      <!--        >导出-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contentinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="id" align="center" prop="id"/>-->
      <el-table-column label="标题" align="center" prop="contentTitle" width="240" />
      <el-table-column label="类型" align="center" prop="contentType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.content_type" :value="scope.row.contentType" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="顺序" align="center" prop="" /> -->
      <el-table-column label="顺序" align="center" prop="weight" sortable="" />
      <el-table-column label="封面" align="center" prop="img" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.img" :width="50" :height="50" />
        </template>
      </el-table-column>
      
      <el-table-column label="封面地址" align="center" prop="img" sortable="" width="300"/>
      
      <el-table-column label="视频地址" align="center" prop="vedioUrl" sortable="" width="300"/>
      
      <el-table-column label="缩略图地址" align="center" prop="abbreviate" sortable="" width="300"/>
      
      <el-table-column label="视频简介" align="center" prop="intro" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.intro | ellipsis }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="userName" width="150" />
      <el-table-column label="昵称" align="center" disabled="disabled" prop="publishNick" width="130" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="100" />
      <!-- <el-table-column label="banner图" align="center" prop="banner" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.banner" :width="50" :height="50"/>
        </template>
      </el-table-column> -->
      <el-table-column label="跳转链接" align="center" prop="bannerUrl" width="150" />
      <el-table-column label="内容模块" align="center" prop="contentCategory" width="100" />
      <el-table-column label="顺序" align="center" prop="weight" sortable="" />
      <el-table-column label="仅会员可见" align="center" prop="onlyVip" :formatter="justVipFormatter" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-info" @click="handleView(scope.row)">查看
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:contentinfo:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:contentinfo:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改内容信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="contentTitle">
          <el-input v-model="form.contentTitle" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="类型" prop="contentType">
          <el-select v-model="form.contentType" filterable placeholder="请选择类型">
            <el-option v-for="dict in dict.type.content_type" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="封面" prop="img">
          <image-upload v-model="form.img" />
        </el-form-item> -->

        <el-form-item label="封面" prop="img">
          <!-- <image-upload v-model="form.img" :action="upUrl" name="multipartFile"/> -->
          <el-upload class="upload-demo" :action="upUrl" v-model="form.img" name="multipartFile" :on-change="onChangeFile"
            ref="uploadComp" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove"
            :limit="2" :on-exceed="handleExceed" :on-success="hanldeSuccess1" :headers="headers" :show-file-list="true"
            :auto-upload="true">
            <el-button type="warning" plain icon="el-icon-upload" size="mini" @click="handleImportMusic">封面</el-button>
          </el-upload>
        </el-form-item>

        <el-form-item label="视频简介" prop="intro" v-show="form.contentType == 1">
          <el-input v-model="form.intro" placeholder="请输入简介" type="textarea" />
        </el-form-item>

        <el-form-item label="视频简介" prop="intro" v-show="form.contentType == 2">
          <el-input v-model="form.intro" placeholder="请输入简介" type="textarea" />
        </el-form-item>

        <el-form-item label="电话" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入手机号" @blur="getNickName" />
        </el-form-item>
        <el-form-item label="用户名" prop="publishNick">
          <el-input v-model="form.publishNick" disabled="disabled" placeholder="发布者昵称" />
        </el-form-item>
        <el-form-item label="图片" prop="banner">
          <!-- <image-upload v-model="form.banner" :action="upUrl" name="multipartFile"/> -->
          <el-upload class="upload-demo" :action="upUrl" v-model="form.banner" name="multipartFile"
            :on-change="onChangeFile" ref="uploadComp1" :on-preview="handlePreview" :on-remove="handleRemove"
            :before-remove="beforeRemove" :limit="2" :on-exceed="handleExceed" :on-success="hanldeSuccess2"
            :headers="headers" :show-file-list="true" :auto-upload="true">
            <el-button type="warning" plain icon="el-icon-upload" size="mini" @click="handleImportMusic">图片</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="链接" prop="bannerUrl">
          <el-input v-model="form.bannerUrl" placeholder="请输入跳转链接" />
        </el-form-item>

        <el-form-item label="模块" prop="contentCategory">
          <el-select v-model="form.categoryIds" placeholder="请选择内容模块" multiple>
            <el-option v-for="dict in contentCategorys" :key="dict.id" :label="dict.name" :value="dict.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="顺序" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入顺序" />

        </el-form-item>

        <el-form-item label="会员可见">
          <el-radio-group v-model="form.onlyVip">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-show="form.contentType == 0" label="富文本内容">
          <editor v-model="form.textContent" :min-height="192" />

        </el-form-item>

        <el-form-item v-if="form.contentType == 1" label="视频url" prop="vedioUrl">
          <!-- <file-upload :fileType="fileType" :fileSize="fileSize" v-model="form.vedioUrl" :action="upUrl" name="multipartFile"/> -->
          <el-upload class="upload-demo" :fileType="fileType" :fileSize="fileSize" :action="upUrl" v-model="form.vedioUrl"
            name="multipartFile" ref="uploadComp2" :on-change="onChangeFile" :on-preview="handlePreview"
            :on-remove="handleRemove" :before-remove="beforeRemove" :limit="2" :on-exceed="handleExceed"
            :on-success="hanldeSuccess3" :headers="headers" :show-file-list="true" :auto-upload="true">
            <el-button type="warning" plain icon="el-icon-upload" size="mini" @click="handleImportMusic">视频url</el-button>
          </el-upload>
        </el-form-item>

        <el-form-item v-if="form.contentType == 2" label="视频url" prop="vedioUrl">
          <!-- <file-upload :fileType="fileType" :fileSize="fileSize" v-model="form.vedioUrl" :action="upUrl" name="multipartFile"/> -->
          <el-upload class="upload-demo" :fileType="fileType" :fileSize="fileSize" :action="upUrl" v-model="form.vedioUrl"
            name="multipartFile" ref="uploadComp3" :on-change="onChangeFile" :on-preview="handlePreview"
            :on-remove="handleRemove" :before-remove="beforeRemove" :limit="2" :on-exceed="handleExceed"
            :on-success="hanldeSuccess4" :headers="headers" :show-file-list="true" :auto-upload="true">
            <el-button type="warning" plain icon="el-icon-upload" size="mini" @click="handleImportMusic">视频url</el-button>
          </el-upload>
        </el-form-item>

         <el-form-item label="视频封面" prop="abbreviate">
          <!-- <file-upload :fileType="fileType" :fileSize="fileSize" v-model="form.vedioUrl" :action="upUrl" name="multipartFile"/> -->
          <el-upload class="upload-demo" :fileType="fileType" :fileSize="fileSize" :action="upUrl" v-model="form.abbreviate"
            name="multipartFile" ref="uploadComp5" :on-change="onChangeFile" :on-preview="handlePreview"
            :on-remove="handleRemove" :before-remove="beforeRemove" :limit="2" :on-exceed="handleExceed"
            :on-success="hanldeSuccess5" :headers="headers" :show-file-list="true" :auto-upload="true">
            <el-button type="warning" plain icon="el-icon-upload" size="mini" @click="handleImportMusic">封面缩略图</el-button>
          </el-upload>
        </el-form-item>

        <el-form-item label="图集" prop="imageList" v-if="form.contentType == 3">

          <el-upload v-model="imageList" ref="uploadComp4" name="multipartFile" :action="upUrl" list-type="picture-card"
            :on-preview="handlePictureCardPreview" :on-success="imgSuccess" :on-error="imgError" :on-remove="imgRemove">
            <i class="el-icon-plus"></i>
            <!-- <img :src="imageList.imgUrl" alt=""> -->
            <!-- <img v-if="imgUrl" :src="imgUrl" class="avatar"> -->
            <!-- <div v-for="(item, index) in form.imageList" :key="index"> -->
              
            <!-- </div> -->
          </el-upload>
          <img class="avatar" v-for="(item, index) in form.imageList" :key="index" :src="form.imageList[index].imgUrl" alt="" >
          <template v-for="(item, index) in changeList">
            <el-form-item :label="`图片简介${index + 1}`">
              <el-input placeholder="请输入图片简介" v-model="introduces[index].introduce"></el-input>
            </el-form-item>
          </template>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listContentinfo,
  getContentinfo,
  delContentinfo,
  addContentinfo,
  updateContentinfo
} from "@/api/system/contentinfo";
import { listContentCategory } from "../../../api/system/contentCategory";
import { getNickName } from "../../../api/system/user";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
// import { Uploads } from '@/api/hpms/qiniu'

import Quill from 'quill';
import { quillEditor } from "vue-quill-editor";
//行高
import { lineHeightStyle } from '@/utils/lineHeight'

var fonts = ['Microsoft-YaHei', 'SimSun', 'SimHei', 'KaiTi', 'Arial', 'Times-New-Roman'];
var Font = Quill.import('formats/font');
Font.whitelist = fonts; //将字体加入到白名单
export default {
  name: "Contentinfo",
  components: {
    quillEditor
  },
  dicts: ['content_type'],
  data() {
    return {
      editorOption: {
        modules: {
          toolbar: [
            ["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
            ["blockquote", "code-block"], //引用，代码块
            [{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
            [{ list: "ordered" }, { list: "bullet" }], //列表
            [{ script: "sub" }, { script: "super" }], // 上下标
            [{ indent: "-1" }, { indent: "+1" }], // 缩进
            [{ direction: "rtl" }], // 文本方向
            [{ size: ['12px', '14px', '16px', '18px', '22px', '26px', '30px', '36px', '42px'] }], // 字体大小
            [{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题
            [{ color: [] }, { background: [] }], // 字体颜色，字体背景颜色
            [{ font: fonts }], // 字体种类
            [{ align: [] }], //对齐方式
            ["clean"], //清除字体样式
            ["image", "video"], //上传图片、上传视频
            [{ lineheight: ["1", "1.5", "1.75", "2", "3", "4", "5"] }], // 对齐方式

          ],
          handlers: {
            lineheight: (value) => {
              if (value) {
                let quill = this.$refs.myQuillEditor.quill;
                quill.format("lineHeight", value);
              }
            },
          },

          handlers: {
            lineheight: (value) => {
              if (value) {
                let quill = this.$refs.myQuillEditor.quill;
                quill.format("lineHeight", value)
              }
            }
          },


        },
        history: {}
      },

      upUrl: process.env.VUE_APP_BASE_API + '/v1/app/public/upload',

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //图集
      imageList: "",
      // 图集简介
      introduces: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 内容信息表格数据
      contentinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      onlyview: false,
      imgUrl: '',
      //
      contentType: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contentTitle: null,
        contentType: null,
        img: null,
        userName: null,
        publishNick: null,
        banner: null,
        bannerUrl: null,
        contentCategory: null,
        weight: null,
        onlyVip: null,
        status: null,
        textContent: null,
        viewNumber: null,
        commentNum: null,
        vedioUrl: null,
        imageList: null
      },
      // 表单参数
      form: {
        weight: 500,
        categoryIds: []
      },
      // 表单校验
      rules: {},
      fileType: ['mp4'],
      fileSize: 500,
      contentCategorys: []
    };
  },

  filters: {
    ellipsis(value) {
      if (!value) return '';
      if (value.length > 10) {
        return value.slice(0, 10) + '...'
      }
      return value
    }
  },

  created() {
    this.getList();
    this.getContentCategory();

  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    },
    changeList() {
      let str = "";
      if (Array.isArray(this.imageList)) {
        str = this.imageList.join(',')
      }
      else {
        str = this.imageList
      }
      let arr = str.split(',').filter((item) => item != '');
      console.log(arr);
      this.introduces = arr.map(() => ({ introduce: '' })); // 确保introduces数组正确填充
      console.log(this.introduces); // 添加调试语句
      for (let i = 0; i < arr.length; i++) {
        this.introduces.push({ introduce: '' })
      }
      console.log(this.introduces)
      return arr;
    }
  },
  methods: {
    imgSuccess(res, file, fileList) {
      console.log(this.imageList)
      this.imageList.push(res.data.url)
      console.log(this.imageList)
    },
      // // 删除图片
    // imgRemove(file, fileList) {
    //   this.imageList = fileList;
    // },
    //   handleSuccess(response, file, fileList) {
    // if (response.code === 200) {
    //   if (this.form.contentType === 3) {
    //     this.form.imageList.imgUrl = response.data.url;
    //   } else {
    //     if (Array.isArray(response.data)) {
    //       let newImages = response.data.map(item => ({ imgUrl: item.fileName }));
    //       this.form.imageList = this.form.imageList.concat(newImages);
    //     } else {
    //       this.form.imageList.push({ imgUrl: response.data.fileName });
    //     }
    //     }
    //   }
    // },

    // handleSuccess(response, file, fileList) {
    //   // 处理成功上传
    //   if (response.code === 200) {
    //     // 假设您的API响应包含已上传文件的URL
    //     // this.form.imgUrl = response.data.url;
    //     this.form.imageList.push({
    //       imgUrl: response.data.url,

    //     })
    //     this.$message.success('上传成功');
    //   } else {
    //     this.$message.error('上传失败');
    //   }
    // },
    onEditorReady(quill) {
      console.log("editor ready!", quill);
    },
    onEditorBlur(quill) {
      console.log("editor blur!", quill);
    },
    onEditorFocus(quill) {
      console.log("editor focus!", quill);
    },

    onEditorChange({ quill, html, text }) {
      console.log("editor change!", quill, html, text);
      this.form.textContent = html;
    },
    ready() {
      Quill.register({ "formats/lineHeight": lineHeightStyle }, true);
    },
    /** 查询内容信息列表 */
    getList() {
      this.loading = true;
      listContentinfo(this.queryParams).then(response => {
        this.contentinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      // this.$refs.uploadComp.clearFiles()
      // this.$refs.uploadComp1.clearFiles()
      // this.$refs.uploadComp2.clearFiles()
      // this.$refs.uploadComp3.clearFiles()
      // this.$refs.uploadComp4.clearFiles()
       this.$refs.uploadComp5.clearFiles()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contentTitle: null,
        contentType: null,
        img: null,
        userName: null,
        publishNick: null,
        banner: null,
        bannerUrl: null,
        contentCategory: null,
        categoryIds: [],
        onlyVip: null,
        status: null,
        textContent: null,
        createTime: null,
        viewNumber: null,
        commentNum: null,
        vedioUrl: null,
        abbreviate:null,
        weight: 500
      };
      //图集
      this.imageList = [],
        this.onlyview = false
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },







    handleImportMusic() {

      console.log("~~@@@@@@~~~~~")
    },
    handleRemove(multipartFile, multipartFileList) {
      console.log(multipartFile, multipartFileList);
    },
    handlePreview(multipartFile) {
      console.log(multipartFile);
    },
    handleExceed(multipartFiles, multipartFileList) {
      // this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${multipartFiles.length} 个文件，共选择了 ${multipartFiles.length + multipartFileList.length} 个文件`);
    },
    beforeRemove(multipartFile, multipartFileList) {
      return this.$confirm(`确定移除 ${multipartFile.name}？`);
    },
    hanldeSuccess(response, multipartFile, multipartFileList) {
      //     if (response.code === 200) {
      //   // this.imageList=response.data.url;
      //   this.imageList.push({
      //     imgUrl: response.data.url,
      //     introduce:this.introduces.introduce
      //   });
      //   this.form.imageList = this.imageList
      // }
      this.getList()
      // if (response && response.data && response.data.url) {
      //   this.form.imageList.push({
      //     imgUrl: response.data.url,
      //   });
      //   this.$message.success('上传成功');
      //   this.getList(); // 如果需要更新其他相关数据，可以在这里调用相应的方法
      // } else {
      //   this.$message.error('上传失败');
      // }
    },
    hanldeSuccess1(res, multipartFile, multipartFileList) {
      if (res.code == 200) {
        this.form.img = res.data.url
      };
    },
    hanldeSuccess2(res, multipartFile, multipartFileList) {
      if (res.code == 200) {
        this.form.banner = res.data.url
      }
    },
    hanldeSuccess3(res, multipartFile, multipartFileList) {
      if (res.code == 200) {
        this.form.vedioUrl = res.data.url
      }
    },
    hanldeSuccess4(res, multipartFile, multipartFileList) {
      if (res.code == 200) {
        this.form.vedioUrl = res.data.url
      }
    },
    hanldeSuccess5(res, multipartFile, multipartFileList) {
      if (res.code == 200) {
        this.form.abbreviate = res.data.url
      }
    },
    onChangeFile(multipartFile, multipartFileList) {
      // if (multipartFileList.length > 1 && multipartFile.status !== "fail") {
      //   multipartFileList.splice(0, 1);
      // }

    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加内容信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids

      // if(Array.isArray(this.form.imageList)){
      //   this.imageList = this.form.imageList.map(item=>item.imgUrl).join(',')
      // }
      if (Array.isArray(this.form.imageList)) {
        this.imageList = this.form.imageList.map(item => item.imgUrl).join(',');
      }

      getContentinfo(id).then(response => {
        this.form = response.data;
        for (let i = 0; i < this.form.imageList.length; i++) {
          let obj = this.form.imageList[i];
          this.imageList = this.imageList + obj.imgUrl
          if (i != this.form.imageList.length - 1) {
            this.imageList = this.imageList + ','
          }
        }
        this.open = true;
        // this.onlyview = true;
        this.title = "修改内容信息";
      });
    },

    //     handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids;
    //   getContentinfo(id).then(response => {
    //     this.form = response.data;
    //     this.imageList = this.form.imageList.join(','); // Set imageList directly from response
    //     if (this.form.contentType === 2) {
    //       this.form.vedioUrl = response.data.vedioUrl; // Set vedioUrl based on contentType
    //     }
    //     this.open = true;
    //     this.onlyview = true;
    //     this.title = "内容信息";
    //   });
    // },
    //     handleView(row) {
    //   this.reset();
    //   const id = row.id || this.ids;
    //   getContentinfo(id).then(response => {
    //     this.form = response.data;
    //     if (Array.isArray(this.form.imageList)) {
    //       this.imageList = this.form.imageList.join(',');
    //     }
    //     this.open = true;
    //     this.onlyview = true;
    //     this.title = "内容信息";
    //   });
    // },
    handleView(row) {
      console.log(row)
      this.reset();
      const id = row.id || this.ids
      getContentinfo(id).then(response => {
        this.form = response.data;
        for (let i = 0; i < this.form.imageList.length; i++) {
          let obj = this.form.imageList[i];
          this.imageList = this.imageList + obj.imgUrl
          if (i != this.form.imageList.length - 1) {
            this.imageList = this.imageList + ','
          }
        }
        this.open = true;
        this.onlyview = true;
        this.title = "内容信息";
      });
    },




    /** 提交按钮 */
    submitForm() {
      let that = this
      this.$refs["form"].validate(valid => {
        // if (that.imageList && that.imageList.length > 0) {
        if (that.imageList && typeof that.imageList === 'string') {

          let imgs = that.imageList.split(',');
          that.form.imageList = imgs; // 将结果赋给 form.imageList
          let imgList = new Array()
          for (let i = 0; i < imgs.length; i++) {
            let obj = {
              imgUrl: imgs[i],
              imgOrder: i,
              introduce: this.introduces[i].introduce
            }
            imgList.push(obj)
            console.log(imgList)
          }
          this.form.imageList = imgList
        }else{
          let imgs = that.imageList
          that.form.imageList = imgs; // 将结果赋给 form.imageList
          let imgList = new Array()
          for (let i = 0; i < imgs.length; i++) {
            let obj = {
              imgUrl: imgs[i],
              imgOrder: i,
              introduce: this.introduces[i].introduce
            }
            imgList.push(obj)
            console.log(imgList)
          }
          this.form.imageList = imgList
        }
        if (valid) {
          // this.form.imageList = this.imageList;

          if (this.form.id != null) {
            updateContentinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form)
            addContentinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.$refs.uploadComp.clearFiles()
              this.$refs.uploadComp1.clearFiles()
              this.$refs.uploadComp2.clearFiles()
              this.$refs.uploadComp3.clearFiles()
              this.$refs.uploadComp4.clearFiles()
              this.$refs.uploadComp5.clearFiles()


            });
          }
        }
      });
    },






    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除内容信息编号为"' + ids + '"的数据项？').then(function () {
        return delContentinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contentinfo/export', {
        ...this.queryParams
      }, `contentinfo_${new Date().getTime()}.xlsx`)
    },
    getContentCategory() {
      listContentCategory().then(res => {
        console.log(res)
        if (res.code == 200) {
          this.contentCategorys = res.data;
        }
      })
    },
    justVipFormatter(row, col) {
      if (row.status == 1) {
        return '是'
      } else {
        return '否'
      }
    },
    getNickName() {
      let userName = this.form.userName
      getNickName(userName).then(res => {
        if (res.code = 200) {
          this.form.publishNick = res.msg
        }
      })
    }
  }
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 150px;
  height: 150px;
  display: inline-block;
  margin-right: 10px;
  /* display: flex; */
}

.ql-container {
  height: 350px;
  font-size: 12px;
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-label::before {
  content: "行高";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1"]::before {
  content: "1";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1.5"]::before {
  content: "1.5";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1.75"]::before {
  content: "1.75";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="2"]::before {
  content: "2";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="3"]::before {
  content: "3";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="4"]::before {
  content: "4";
}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="5"]::before {
  content: "5";
}

.ql-snow .ql-picker.ql-lineheight {
  width: 70px;
}
</style>
